<!-- 修改代理的信息 -->
<div class="alert-title">修改代理</div>

<table class="daili-info">
    <tr>
        <td class="title">账号</td>
        <td class="field state">
            <span class="account"></span><br>
            <label class="am-radio-inline">
                <input type="radio" name="state" value="0" data-am-ucheck> 正常
            </label>
            <label class="am-radio-inline">
                <input type="radio" name="state" value="1" data-am-ucheck> 冻结
            </label>
            <label class="am-radio-inline">
                <input type="radio" name="state" value="2" data-am-ucheck> 停用
            </label>
        </td>
        <td class="copy"></td>
    </tr>
    <tr class="hideWhenDetail">
        <td class="title">登录密码</td>
        <td class="field login-password">
            <input type="password" class="am-form-field" name="login-password" placeholder="留空为不修改"/>
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">真实姓名</td>
        <td class="field">
            <input type="text" class="am-form-field ui_name" name="realname" placeholder="请输入用户的真实姓名">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">用户组</td>
        <td class="field">
            <select data-am-selected class="ui_grade">
                <option value="0" selected>普通会员</option>
                <option value="49">代理</option>
            </select>
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">开户银行</td>
        <td class="field">
            <select data-am-selected class="banklist ui_bank">
            </select>
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">银行账号</td>
        <td class="field">
            <input type="text" class="am-form-field ui_bank_account" name="bank-account" placeholder="请输入银行账号">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">支付地址</td>
        <td class="field">
            <input type="text" class="am-form-field ui_bank_addr" name="bank-addr" placeholder="请输入开户银行地址">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">电话</td>
        <td class="field">
            <input type="number" class="am-form-field ui_phone" name="phone" placeholder="请输入用户的手机号">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">E-mail</td>
        <td class="field">
            <input type="text" class="am-form-field ui_email" name="email" placeholder="请输入用户的邮箱地址">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">QQ</td>
        <td class="field">
            <input type="number" class="am-form-field ui_qq" name="qq" placeholder="请输入用户的QQ号码">
        </td>
        <td class="copy"></td>
    </tr>

    <tr  class="hideWhenDetail">
        <td class="title">提款密码</td>
        <td class="field">
            <input type="password" class="am-form-field" name="take-password" placeholder="留空为不修改">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">备注</td>
        <td class="field">
            <input type="text" class="am-form-field ui_memo" name="memo">
        </td>
        <td class="copy"></td>
    </tr>

    <tr>
        <td class="title">代理模式</td>
        <td class="field peilv">
            <label class="am-radio-inline">
                <input type="radio" name="peilv" value="2" data-am-ucheck checked> 分红
            </label>
            <label class="am-radio-inline">
                <input type="radio" name="peilv" value="1" data-am-ucheck> 赔率差
            </label>
        </td>
        <td class="copy"></td>
    </tr>

    <tr class="hide referee-readonly">
        <td class="title">行政费用</td>
        <td class="field admin-rate">
        </td>
        <td class="copy"></td>
    </tr>
    <tr class="hide referee-readonly">
        <td class="title">风险费用</td>
        <td class="field risk-rate">
        </td>
        <td class="copy"></td>
    </tr>
    <tr class="hide referee-readonly bonus-rate-c">
        <td class="title">分红比例</td>
        <td class="field bonus-rate">
        </td>
        <td class="copy"></td>
    </tr>
</table>

<div class="button_line">
    <button class="btn-save admin_button">确定</button>
    <button class="close admin_button">取消</button>
</div>
<style type="text/css">
    .daili-info .title {
        width: 100px !important;
    }
    .daili-info {
        width: 100%;
    }
    .daili-info td { padding: 5px; }
    .hide {
        display: none;
    }
</style>

<script>
    $(".banklist").selected();
    Util.fillBanks($(".banklist"));
    
    // 填充用户信息
    var u = context.center.referee;
    $(".daili-info .account").html(u.mobile);
    if (u.state == 0) {
        $(".state input[value='0']").uCheck('check');
        $(".state input[value='1']").uCheck('uncheck');
        $(".state input[value='2']").uCheck('uncheck');
    }
    else if (u.state == 1) {
        $(".state input[value='1']").uCheck('check');
        $(".state input[value='0']").uCheck('uncheck');
        $(".state input[value='2']").uCheck('uncheck');
    }
    else if (u.state == 2) {
        $(".state input[value='1']").uCheck('uncheck');
        $(".state input[value='0']").uCheck('uncheck');
        $(".state input[value='2']").uCheck('check');
    }

    $(".daili-info input[name='realname']").val(u.name || '');
    $(".ui_qq").val(context.center.referee.qq || '');
    $(".ui_grade").val(u.grade == 49 ? "49" : "0");

    // 银行信息
    var ui_bankInfo = {};
    if (u.bank) {
        ui_bankInfo = JSON.parse(u.bank);
    }
    $(".daili-info .banklist").val(ui_bankInfo.addr || '');
    $(".daili-info input[name='bank-account']").val(ui_bankInfo.account || '');
    $(".daili-info input[name='bank-addr']").val(ui_bankInfo.addr || '');
    if (ui_bankInfo.bank) {
        $(".ui_bank").val(ui_bankInfo.bank);
    }

    $(".daili-info input[name='phone']").val(u.phone || '');
    $(".daili-info input[name='email']").val(u.email2 || '');
    $(".daili-info input[name='memo']").val(u.memo || '');

    // 代理配置
    if (!u.adminFee || u.adminFee == '0')
        $(".daili-info .admin-rate").html('系统默认');
    else
        $(".daili-info .admin-rate").html((u.adminFee / 100).toFixed(2));
    if (!u.riskFee || u.riskFee == '0')
        $(".daili-info .risk-rate").html('系统默认');
    else
        $(".daili-info .risk-rate").html((u.riskFee / 100).toFixed(2));
    if (!u.bonusRate || u.bonusRate == '0')
        $(".daili-info .bonus-rate").html('系统默认');
    else
        $(".daili-info .bonus-rate").html((u.bonusRate * 100).toFixed(2) + "%");
        
// 是否开启修改赔率: TODO
    if (u.refereeType != '1') {
        // 关闭赔率
        $(".peilv input[value='2']").uCheck('check');
        $(".peilv input[value='1']").uCheck('uncheck');
    }
    else {
        $(".peilv input[value='1']").uCheck('check');
        $(".peilv input[value='2']").uCheck('uncheck');
    }

    $(".button_line .close").click(function() {
        $("#modify_daili_info").remove();
    });
    $(".button_line .btn-save").click(function() {
        // 是否有修改登录密码
        var arr = [];

        var v = $(".daili-info input[name='login-password']").val().trim();
        if (v && !confirm("是否将用户的登录密码修改为：" + v + "？")) return;
        if (v) {
            arr.push(function(cb) {
                CMD.reset_password(u.id, $(".daili-info input[name='login-password']").val().trim(), cb);
            })
        }

        // 是否有修改取款密码
        var data = {};
        var v = $(".daili-info input[name='take-password']").val().trim();
        if (v && !confirm("是否将用户的取款密码修改为：" + v + "？")) return;
        if (v) data.tpassword = v;

        // 冻结/解冻账号
        var v = $(".daili-info .state input:checked").val();
        if (v != u.state) {
            arr.push(function(cb) {
                CMD.user_state(u.id, $(".daili-info .state input:checked").val(), cb);
            })
        }
        
        // 修改代理的类型
        if ($(".peilv input:checked").val() != u.refereeType) {
            arr.push(function(cb) {
                CMD.user_referee_type(u.id, $(".peilv input:checked").val(), cb);
            })
        }

        // 用户组
        var v = $(".user-info .ui_grade").val();
        if (v == 49 && ui.grade != 49 || v == 1 && ui.grade == 49) {
            arr.push(function(cb) {
                CMD.user_grade(u.id, $(".user-info .ui_grade").val(), cb);
            })
        }

        // 其他信息
        var v = $(".daili-info .ui_name").val().trim();
        if (v != u.name) data.name = v;
        var v = $(".daili-info .ui_qq").val().trim();
        if (v != u.qq) data.qq = v;
        var v = $(".daili-info .ui_phone").val().trim();
        if (v != u.phone) data.phone = v;
        var v = $(".daili-info .ui_email").val().trim();
        if (v != u.email2) data.email2 = v;
        var v = $(".daili-info .ui_memo").val().trim();
        if (v != u.memo) data.memo = v;
        
        // 银行信息
        ui_bankInfo = {};
        ui_bankInfo.bank = $(".ui_bank").val();
        ui_bankInfo.addr = $(".ui_bank_addr").val().trim();
        ui_bankInfo.account = $(".ui_bank_account").val().trim();
        var v = JSON.stringify(ui_bankInfo);
        if (data.bank != v)
            data.bank = v;
        
        if (!Util.isEmpty(data)) {
            arr.push(function(cb) {
                CMD.modify_user_info(u.id, data, cb);
            })
        }

        // 保存信息
        startLoading();
        Util.multiFuncs(arr, function() {
            stopLoading();
            $("#modify_daili_info").remove();
            _f();
        });
    });

    if (context.center.refereeOper == "detail") {
        $(".button_line .btn-save").hide();
        $(".alert-title").html("查看详情");
        $(".hideWhenDetail").hide();
        $(".referee-readonly").show();
        if (u.refereeType == 1) {
            $(".bonus-rate-c").hide();
        }
    }
    else {
        $(".referee-readonly").hide();
    }
</script>